package com.zyg.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyg.dao.UserMapper;
import com.zyg.pojo.User;
import com.zyg.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    private final UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public Page<User> getUserPage(int pageNum, int pageSize, String name, String identificationNumber) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();

        // 动态添加查询条件
        if (name != null && !name.isEmpty()) {
            queryWrapper.like("name", name);
        }
        if (identificationNumber != null && !identificationNumber.isEmpty()) {
            queryWrapper.like("identification_number", identificationNumber);
        }

        // 分页查询
        Page<User> page = new Page<>(pageNum, pageSize);
        return userMapper.selectPage(page, queryWrapper);
    }
}
